package com.example.manage.controller;

import com.example.manage.bean.CarportBean;
import com.example.manage.bean.ResultBean;
import com.example.manage.bean.UserBean;
import com.example.manage.mapper.CarportMapper;
import com.example.manage.mapper.UserMapper;
import com.example.manage.utils.MD5Util;
import com.example.manage.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@Controller
@RequestMapping("/carport")
public class CarportController {

    @Autowired
    CarportMapper carportMapper;

    @RequestMapping("/addCarport")
    @ResponseBody
    public ResultBean addCarport(@RequestBody CarportBean carportBean) {
        CarportBean bean = carportMapper.getCarportByNumber(carportBean.getNumber());
        if (bean != null) {
          return   ResultUtil.getFailBean("该编号已存在，请修改后提交");
        }
        int count = carportMapper.addCarport(carportBean);
        return ResultUtil.getResultBean(count, "添加失败");
    }

    @RequestMapping("/updateCarport")
    @ResponseBody
    public ResultBean updateCarport(@RequestBody CarportBean carportBean) {
        int count = carportMapper.updateCarport(carportBean);
        return ResultUtil.getResultBean(count, "修改失败");
    }

    @RequestMapping("/deleteCarport")
    @ResponseBody
    public ResultBean deleteCarport(@RequestBody Map<String, Integer> params) {
        int count = carportMapper.deleteCarport(params.get("id"));
        return ResultUtil.getResultBean(count, "删除失败");
    }

    @RequestMapping("/getCarport")
    @ResponseBody
    public ResultBean getCarport() {
        List<CarportBean> carport = carportMapper.getCarport();
        return ResultUtil.getSuccessBean(carport);
    }


}
